package java8.chapter11.test;

import static java8.chapter11.test.Util.delay;
import static java8.chapter11.test.Util.format;

import java.util.Random;

public class Shop {

	private final String name;
	private final Random random;
	
	public Shop(String name) {
		this.name = name;
		random = new Random(name.charAt(0) * name.charAt(1) * name.charAt(2));
	}
	
	public String getPrice(String product) {
		double price = calculatPrice(product);
		Discount.Code code = Discount.Code.values()[random.nextInt(Discount.Code.values().length)];
		return name + ":" + price + ":" + code; 
	}

	public double calculatPrice(String product) {
		delay();
		return format(random.nextDouble() * product.charAt(0) + product.charAt(1));
	}

	public String getName() {
		return name;
	}
	
}